/**
 * Created by box on 2017/3/11.
 */
var express = require('express');
var fortune = require('./lib/fortune');
var app = express();

var handlebars = require('express3-handlebars').create({
    defaultLayout : 'main',
    extname : '.hbs'
});
app.engine('handlebars', handlebars.engine);

app.set('view engine', 'handlebars');

app.set('port', process.env.PORT || 9999);

app.use(express.static(__dirname + '/public'));

app.get('/', function (req, res) {
    res.render('home');
});

app.get('/about', function (req, res) {
    var randomFortune = fortune.getFortune();
    res.render('about',{fortune : randomFortune});
});

app.use(function (req, res, next) {
    res.status(404).render('404');
});

app.use(function (err, req, res, next) {
    console.error(err.stack);
    res.status(500).render('500');
});

